package com.ruoyi.system.service.impl;

import java.io.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.ValidationException;

import com.ruoyi.common.utils.PicUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.QxChestnutAdoptModel;
import com.ruoyi.system.domain.QxChestnutAdoptModelHistory;
import com.ruoyi.system.domain.vo.ExportExcelModelListVO;
import com.ruoyi.system.mapper.QxChestnutAdoptModelMapper;
import com.ruoyi.system.service.IQxChestnutAdoptModelHistoryService;
import com.ruoyi.system.service.IQxChestnutAdoptModelService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.ValidationException;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;

/**
 * 板栗树认领主Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-07-28
 */
@Service
public class QxChestnutAdoptModelServiceImpl implements IQxChestnutAdoptModelService {
	@Autowired
	private QxChestnutAdoptModelMapper qxChestnutAdoptModelMapper;

	@Autowired
	private IQxChestnutAdoptModelHistoryService adoptModelHistoryService;

	private Logger logger = LoggerFactory.getLogger(QxChestnutAdoptModelServiceImpl.class);
	private final static String THREE_PATH = "//threeImages//";

	/**
	 * 查询板栗树认领主
	 *
	 * @param treeId 板栗树认领主主键
	 * @return 板栗树认领主
	 */
	@Override
	public QxChestnutAdoptModel selectQxChestnutAdoptModelByTreeId(Long treeId) {
		QxChestnutAdoptModel model = qxChestnutAdoptModelMapper.selectQxChestnutAdoptModelByTreeId(treeId);
		setImagesOne(model);
		return model;

	}

	/**
	 * 查询板栗树认领主列表
	 *
	 * @param qxChestnutAdoptModel 板栗树认领主
	 * @return 板栗树认领主
	 */
	@Override
	public List<QxChestnutAdoptModel> selectQxChestnutAdoptModelList(QxChestnutAdoptModel qxChestnutAdoptModel) {
		List<QxChestnutAdoptModel> list = qxChestnutAdoptModelMapper
				.selectQxChestnutAdoptModelList(qxChestnutAdoptModel);
		setImagesList(list);
		return list;
	}

	public void setImagesList(List<QxChestnutAdoptModel> list) {
		list.forEach(c -> {
			if (StringUtils.isNotEmpty(c.getSpringImages())) {
				List<String> springs = JSON.parseArray(c.getSpringImages(), String.class);
				c.setSpringImagesList(springs);
			}
			if (StringUtils.isNotEmpty(c.getAutumnImages())) {
				List<String> autumn = JSON.parseArray(c.getAutumnImages(), String.class);
				c.setAutumnImagesList(autumn);
			}
			if (StringUtils.isNotEmpty(c.getSummerImages())) {
				List<String> sum = JSON.parseArray(c.getSummerImages(), String.class);
				c.setSummerImagesList(sum);
			}
			if (StringUtils.isNotEmpty(c.getWinterImages())) {
				List<String> winter = JSON.parseArray(c.getWinterImages(), String.class);
				c.setWinterImagesList(winter);
			}

		});
	}

	public void setImagesOne(QxChestnutAdoptModel c) {

		if (StringUtils.isNotEmpty(c.getSpringImages())) {
			List<String> springs = JSON.parseArray(c.getSpringImages(), String.class);
			c.setSpringImagesList(springs);
		}
		if (StringUtils.isNotEmpty(c.getAutumnImages())) {
			List<String> autumn = JSON.parseArray(c.getAutumnImages(), String.class);
			c.setAutumnImagesList(autumn);
		}
		if (StringUtils.isNotEmpty(c.getSummerImages())) {
			List<String> sum = JSON.parseArray(c.getSummerImages(), String.class);
			c.setSummerImagesList(sum);
		}
		if (StringUtils.isNotEmpty(c.getWinterImages())) {
			List<String> winter = JSON.parseArray(c.getWinterImages(), String.class);
			c.setWinterImagesList(winter);
		}

	}

	/**
	 * 新增板栗树认领主
	 *
	 * @param qxChestnutAdoptModel 板栗树认领主
	 * @return 结果
	 */
	@Override
	public int insertQxChestnutAdoptModel(QxChestnutAdoptModel qxChestnutAdoptModel) {
		qxChestnutAdoptModel.setCreateTime(DateUtils.getNowDate());
//		String[] s = urlPath.split("/treeImages/");
//		String fileAbPath = RuoYiConfig.getBLImagesPath() + s[1];
//		System.out.println("删除文件");
//		return AjaxResult.success();
		return qxChestnutAdoptModelMapper.insertQxChestnutAdoptModel(qxChestnutAdoptModel);
	}

//	public byte[] get
	/**
	 * 修改板栗树认领主
	 *
	 * @param qxChestnutAdoptModel 板栗树认领主
	 * @return 结果
	 */
	@Override
	public int updateQxChestnutAdoptModel(QxChestnutAdoptModel qxChestnutAdoptModel) {
		qxChestnutAdoptModel.setUpdateTime(DateUtils.getNowDate());
		return qxChestnutAdoptModelMapper.updateQxChestnutAdoptModel(qxChestnutAdoptModel);
	}

	/**
	 * 批量删除板栗树认领主
	 *
	 * @param treeIds 需要删除的板栗树认领主主键
	 * @return 结果
	 */
	@Override
	public int deleteQxChestnutAdoptModelByTreeIds(Long[] treeIds) {
		return qxChestnutAdoptModelMapper.deleteQxChestnutAdoptModelByTreeIds(treeIds);
	}

	/**
	 * 删除板栗树认领主信息
	 *
	 * @param treeId 板栗树认领主主键
	 * @return 结果
	 */
	@Override
	public int deleteQxChestnutAdoptModelByTreeId(Long treeId) {
		return qxChestnutAdoptModelMapper.deleteQxChestnutAdoptModelByTreeId(treeId);
	}

	/**
	 * 导入用户数据
	 *
	 * @param treeChestnutList 用户数据列表
	 * @param isUpdateSupport  是否更新支持，如果已存在，则进行更新数据
	 * @param operName         操作用户
	 * @return 结果
	 */
	@Override
	public String importTreeChestnut(List<QxChestnutAdoptModel> treeChestnutList, Boolean isUpdateSupport,
									 String operName) {
		if (StringUtils.isNull(treeChestnutList) || treeChestnutList.size() == 0) {
			throw new ServiceException("导入数据不能为空！");
		}
		int successNum = 0;
		int failureNum = 0;
		StringBuilder successMsg = new StringBuilder();
		StringBuilder failureMsg = new StringBuilder();
		for (QxChestnutAdoptModel tree : treeChestnutList) {
			try {
				// 验证是否存在这个用户
				QxChestnutAdoptModel t = qxChestnutAdoptModelMapper.selectQxChestnutAdoptModeByCode(tree.getTreeCode());
				if (StringUtils.isNull(t)) {
					tree.setCreateBy(operName);
					qxChestnutAdoptModelMapper.insertQxChestnutAdoptModel(tree);
					successNum++;
					successMsg.append("<br/>" + successNum + "、编号 " + tree.getTreeCode() + " 导入成功");
				} else if (isUpdateSupport) {
					tree.setUpdateBy(operName);
					qxChestnutAdoptModelMapper.updateQxChestnutAdoptModel(tree);
					successNum++;
					successMsg.append("<br/>" + successNum + "、编号 " + tree.getTreeCode() + " 更新成功");
				} else {
					failureNum++;
					failureMsg.append("<br/>" + failureNum + "、编号 " + tree.getTreeCode() + " 已存在");
				}
			} catch (Exception e) {
				failureNum++;
				String msg = "<br/>" + failureNum + "、编号 " + tree.getTreeCode() + " 导入失败：";
				failureMsg.append(msg + e.getMessage());
				logger.error(msg, e);
			}
		}
		if (failureNum > 0) {
			failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
			throw new ServiceException(failureMsg.toString());
		} else {
			successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
		}
		return successMsg.toString();
	}

	/**
	 * 板栗实体导入方法
	 *
	 * @param file
	 * @return
	 */
	@Override
	public String importDataTreeChestnut(MultipartFile file, boolean updateSupport, String userName) {
		// 获取excel解析类
		ExcelUtil<QxChestnutAdoptModel> util = new ExcelUtil<>(QxChestnutAdoptModel.class);
		String msg = "";
		try {
			// 解析excel所有 文本数据
			List<QxChestnutAdoptModel> treeList = util.myImportExcel(file.getInputStream(), 1, 8);
			treeList = qxChestnutAdoptImageExport(file, treeList);
			msg = importTreeChestnut(treeList, updateSupport, userName);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return msg;
	}

	/**
	 * 板栗图片上传
	 *
	 * @param file 上传的图片文件
	 * @return
	 */
	@Override
	public AjaxResult blUploadImage(MultipartFile file) {
		File dir = new File(RuoYiConfig.getProfile() + "/treeImages/" + DateUtils.getDateFormat() + "/");
		if (!dir.exists()) {
			dir.mkdirs();
		}

		String fileName = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()) + 1 + ".jpg";
		String filePath = RuoYiConfig.getBLImagesPath() + DateUtils.getDateFormat() + "/" + fileName; // 文件路径和名称
		String urlPath = Constants.RESOURCE_PREFIX + Constants.BL_DIR_HOLDER + DateUtils.getDateFormat() + "/"
				+ fileName;
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream(filePath);

		} catch (FileNotFoundException ex) {
			throw new RuntimeException(ex);
		} finally {
			try {
				if (fos != null) {
					fos.write(file.getBytes());
				} else {
					logger.warn("输出流为空");
				}
				fos.close();
			} catch (IOException ex) {
				throw new RuntimeException(ex);
			}

		}
		Map<String, String> map = new HashMap<>();
		map.put("urlPath", urlPath);
		map.put("filePath", filePath);
		return AjaxResult.success(map);
	}

	/**
	 * 板栗树图片删除
	 *
	 * @param urlPath
	 * @return
	 */
	@Override
	public AjaxResult blUploadImageRemove(String urlPath) {
		String[] s = urlPath.split("/treeImages/");
		String fileAbPath = RuoYiConfig.getBLImagesPath() + s[1];
		System.out.println("删除文件");
		return AjaxResult.success();
	}

	/**
	 * 下载模板
	 * @param response
	 */
	@Override
	public void importTemplateThreeExcel(HttpServletResponse response) throws IOException {
		response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
		response.setCharacterEncoding("utf-8");
		try (BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(new File(RuoYiConfig.getTreeTemplate()+"迁西板栗导入模板.xlsx")))) {
			// 获取输出流
			ServletOutputStream outStream = response.getOutputStream();
			byte[] buffer = new byte[4096];
			int bytesRead;

			// 将文件内容写入输出流
			while ((bytesRead = inStream.read(buffer)) != -1) {
				outStream.write(buffer, 0, bytesRead);
			}

			// 关闭输出流
			outStream.close();
		} catch (IOException e) {
			e.printStackTrace();
			// 处理异常情况
			response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		}

		}

		/**
		 * 将文件的图片读取入口方法
		 *
		 * @param file     文件
		 * @param treeList 数据集合
		 * @return 返回处理后的数据
		 */
		public List<QxChestnutAdoptModel> qxChestnutAdoptImageExport(MultipartFile file,
				List<QxChestnutAdoptModel> treeList) {
			try {
				String fileName = file.getOriginalFilename();

				File dir = new File(RuoYiConfig.getProfile() + "/treeImages/" + DateUtils.getDateFormat() + "/");
				if (!dir.exists()) {
					dir.mkdirs();
				}
				// 创建一个输入流，读取Excel文件
				// 根据文件后缀创建不同的工作簿对象
				Workbook workbook;
				if (fileName.endsWith(".xls")) {
					workbook = new HSSFWorkbook(file.getInputStream());
					// 获取第一个工作表
					HSSFSheet sheet = (HSSFSheet) workbook.getSheetAt(0);
					Map<String, PictureData> a = ExcelUtil.getSheetPictures03(sheet, (HSSFWorkbook) workbook);
					publicWriteFile(a, treeList);
				} else if (fileName.endsWith(".xlsx")) {
					workbook = new XSSFWorkbook(file.getInputStream());
					// 获取第一个工作表
					XSSFSheet sheet = (XSSFSheet) workbook.getSheetAt(0);
					Map<String, PictureData> a = ExcelUtil.getSheetPictures07(sheet, (XSSFWorkbook) workbook);
					System.out.println(a.size());
					publicWriteFile(a, treeList);
				} else {
					throw new IllegalArgumentException("Invalid Excel file format");
				}
				// 关闭流
				workbook.close();
				file.getInputStream().close();
			} catch (IOException ex) {
				throw new RuntimeException(ex);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return treeList;
		}

		public void publicWriteFile(Map<String, PictureData> a, List<QxChestnutAdoptModel> treeList) {
			int i = 0;
			for (String key : a.keySet()) {
				PictureData data = a.get(key);
				byte[] b = data.getData();
				String fileName = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()) + i + ".jpg";
				String filePath = RuoYiConfig.getBLImagesPath() + DateUtils.getDateFormat() + "/" + fileName; // 文件路径和名称
				String urlPath = Constants.RESOURCE_PREFIX + Constants.BL_DIR_HOLDER + DateUtils.getDateFormat() + "/"
						+ fileName;
				String[] xy = key.split("_");
				Integer x = Integer.valueOf(xy[0]) - 2;
				Integer y = Integer.valueOf(xy[1]);
				if (x >= 0 && ObjectUtils.isNotEmpty(treeList)) {
					// 获取位置的记录 并赋值字段
					imageAssignmentField(treeList.get(x), y, urlPath);
				}
				FileOutputStream fos = null;
				FileOutputStream sfo = null;
				try {
					fos = new FileOutputStream(filePath);
					//如果是空设置缩略图
					if (StringUtils.isEmpty(treeList.get(x).getThumbnail())){
						byte[] end =  PicUtils.compressPicForScale(b,20,"");
						String sPath = RuoYiConfig.getBLImagesPath() + DateUtils.getDateFormat() + "/suolue" + fileName;
						String uPath = Constants.RESOURCE_PREFIX + Constants.BL_DIR_HOLDER + DateUtils.getDateFormat() + "/suolue"
								+ fileName;
						sfo = new FileOutputStream(sPath);
                        treeList.get(x).setThumbnail(uPath);
						if (sfo != null){
							sfo.write(end);
							sfo.close();
						}
					}

				} catch (FileNotFoundException ex) {
					throw new RuntimeException(ex);
				} catch (IOException e) {
					throw new RuntimeException(e);
				} finally {
					try {
						if (fos != null) {
							fos.write(b);
						} else {
							System.out.println("输出流为空");
						}
						fos.close();
					} catch (IOException ex) {
						throw new RuntimeException(ex);
					}

				}
				i++;

			}
		}

		/**
		 * 图片赋值字段
		 */
		public void imageAssignmentField(QxChestnutAdoptModel row, Integer y, String urlPath) {
//        9-11 冬天  12-14 春天 15-17夏天 18-20 秋天
			if (y >= 9 && y <= 11) {
				String path = weatherStringUpdate(row.getWinterImages(), urlPath);
				row.setWinterImages(path);
			}
			if (y >= 12 && y <= 14) {
				String path = weatherStringUpdate(row.getSpringImages(), urlPath);
				row.setSpringImages(path);
			}
			if (y >= 15 && y <= 17) {
				String path = weatherStringUpdate(row.getSummerImages(), urlPath);
				row.setSummerImages(path);
			}
			if (y >= 18 && y <= 20) {
				String path = weatherStringUpdate(row.getAutumnImages(), urlPath);
				row.setAutumnImages(path);
			}
		}

		/**
		 * 天气字符串更新
		 *
		 * @param weather
		 * @param urlPath 存储网络地址
		 */
		public String weatherStringUpdate(String weather, String urlPath) {
			List<String> list = new ArrayList<>();
			if (StringUtils.isNotEmpty(weather)) {
				list = JSON.parseArray(weather, String.class);
				list.add(urlPath);
			} else {
				list = new ArrayList<>();
				list.add(urlPath);
			}
			return JSON.toJSONString(list);
		}

		@Override
		public void apply(QxChestnutAdoptModel qxChestnutAdoptModel) throws Exception {
			try {
				QxChestnutAdoptModel model = this.qxChestnutAdoptModelMapper
						.selectQxChestnutAdoptModelByTreeId(qxChestnutAdoptModel.getTreeId());
				if (model == null) {
					throw new ValidationException("要认养的树苗不存在系统中，可能已经被管理员删除，请重新发起认养申请！");
				}
				if (model.getStatus() != null && model.getStatus() != 0) {
					throw new ValidationException("该树苗已经被认养，请更换树苗重新发起认养申请！");
				}
				qxChestnutAdoptModel.setApplyDate(new Date());
				qxChestnutAdoptModel.setStatus(1);
				this.qxChestnutAdoptModelMapper.updateQxChestnutAdoptModel(qxChestnutAdoptModel);
			} catch (Exception e) {
				throw new ValidationException(e.getMessage());
			}
		}

	@Transactional
	@Override
	public AjaxResult approve(JSONObject paramObj) {
		String msg = "";
		if (paramObj.get("treeId") == null) {
			return AjaxResult.error("请选择要审核的记录");
		}
		System.out.println(paramObj.get("approveId"));
		if (paramObj.get("approveId") == null) {
			return AjaxResult.error("审核结果为空");
		}
		Integer approveId = Integer.valueOf(paramObj.get("approveId").toString());
		QxChestnutAdoptModel model = this.qxChestnutAdoptModelMapper
				.selectQxChestnutAdoptModelByTreeId(Long.valueOf(paramObj.get("treeId").toString()));
		if (model == null) {
			return AjaxResult.error("要认养的板栗树不存在系统中，无法继续");
		}
		if (approveId == 0) {// ==0时为认养审核通过
			if (model.getStatus() != 1) {
				return AjaxResult.error("该板栗树状态不是【认养申请中】的状态，无法继续");
			}
			if (paramObj.get("approveReson") == null) {
				return AjaxResult.error("审核意见为空");
			}
			// 通过
			model.setStartDate(new Date());
			model.setStatus(2);// 更新为已认养
			this.qxChestnutAdoptModelMapper.updateQxChestnutAdoptModel(model);
			msg = "审核通过";
			return AjaxResult.success(msg);
		}
		// 如果是审核不通过或者结束认养，将数据写入到历史表，更新树苗表的状态以及认养人等信息
		QxChestnutAdoptModelHistory qxChestnutAdoptModelHistory = new QxChestnutAdoptModelHistory();
		BeanUtils.copyBeanProp(qxChestnutAdoptModelHistory, model);
		if (approveId == 1) {// =1时为领养审核不通过
			// 审核不通过时判断树苗状态是否 ==1
			if (model.getStatus() != 1) {
				return AjaxResult.error("该板栗树状态不是【认养申请中】的状态，无法继续");
			}
			if (paramObj.get("approveReson") == null) {
				return AjaxResult.error("审核意见为空");
			}
			qxChestnutAdoptModelHistory.setApproveReson(paramObj.get("approveReson").toString());
			qxChestnutAdoptModelHistory.setStatus(1L);// 领养审核不通过
			msg = "审核不通过";
		}
		if (approveId == 2) {// =2时为结束领养
			// 结束领养时判断树苗状态是否等于2，不等于2则不允许结束
			if (model.getStatus() != 2) {
				return AjaxResult.error("该板栗树状态不是【已领养】的状态，无法结束");
			}
			if (paramObj.get("approveReson") == null) {
				return AjaxResult.error("结束原因为空");
			}
			qxChestnutAdoptModelHistory.setStatus(2L);// 结束领养
			msg = "结束认养成功";
		}
		qxChestnutAdoptModelHistory.setEndDate(new Date());// 领养审核不通过
		qxChestnutAdoptModelHistory.setApproveReson(paramObj.get("approveReson").toString());
		// 审核不通过
		// 写入到认养历史记录表中
		adoptModelHistoryService.insertQxChestnutAdoptModelHistory(qxChestnutAdoptModelHistory);
		// 更新主表状态为未认养
		this.qxChestnutAdoptModelMapper.setnullForApply(Long.valueOf(paramObj.get("treeId").toString()));
		return AjaxResult.success(msg);
	}

	@Override
	public void exportModelListToExcelService(HttpServletResponse response, QxChestnutAdoptModel qxChestnutAdoptModel) {
		try {
			System.out.println(DateUtils.getTime());
			// 设置信息头，告诉浏览器内容为excel类型
			response.setHeader("content-Type", "application/vnd.ms-excel");
			// 设置下载名称
			response.setHeader("Content-Disposition",
					"attachment;filename=" + URLEncoder.encode("板栗树列表.xls", StandardCharsets.UTF_8.name()));
			// 字节流输出
			OutputStream out = response.getOutputStream();
			// 设置excel参数
			ExportParams params = new ExportParams();
			// 设置sheet名名称
			params.setSheetName("板栗树列表");
			// 设置标题
			params.setTitle("板栗树列表");
//			// 转成对应的类型;要不然会报错，虽然也可以导出成功
			List<ExportExcelModelListVO> exportList = new ArrayList<ExportExcelModelListVO>();
			List<QxChestnutAdoptModel> qxChestnutAdoptModels = this.selectQxChestnutAdoptModelList(qxChestnutAdoptModel);
			ExportExcelModelListVO exvo = null;
			for (QxChestnutAdoptModel model: qxChestnutAdoptModels) {
				exvo = new ExportExcelModelListVO();
				BeanUtils.copyBeanProp(exvo,model);
//				List<String> splist = exvo.getSpringImagesList();
//				if(splist!=null){
//					exvo.setSpringImage1(splist.size()>=1?buildImgPath(splist.get(0)):"");
//					exvo.setSpringImage2(splist.size()>=2?buildImgPath(splist.get(1)):"");
//					exvo.setSpringImage3(splist.size()>=3?buildImgPath(splist.get(2)):"");
//				}
//				List<String> smlist = exvo.getSummerImagesList();
//				if(smlist!=null){
//					exvo.setSummerImage1(smlist.size()>=1?buildImgPath(smlist.get(0)):"");
//					exvo.setSummerImage2(smlist.size()>=2?buildImgPath(smlist.get(1)):"");
//					exvo.setSummerImage3(smlist.size()>=3?buildImgPath(smlist.get(2)):"");
//				}
//				List<String> autumnImagesList = exvo.getAutumnImagesList();
//				if(autumnImagesList!=null){
//					exvo.setAutumnImage1(autumnImagesList.size()>=1?buildImgPath(autumnImagesList.get(0)):"");
//					exvo.setAutumnImage2(autumnImagesList.size()>=2?buildImgPath(autumnImagesList.get(1)):"");
//					exvo.setAutumnImage3(autumnImagesList.size()>=3?buildImgPath(autumnImagesList.get(2)):"");
//				}
//				List<String> winterImagesList= exvo.getWinterImagesList();
//				if(winterImagesList!=null){
//					exvo.setWinterImage1(winterImagesList.size()>=1?buildImgPath(winterImagesList.get(0)):"");
//					exvo.setWinterImage2(winterImagesList.size()>=2?buildImgPath(winterImagesList.get(1)):"");
//					exvo.setWinterImage3(winterImagesList.size()>=3?buildImgPath(winterImagesList.get(2)):"");
//				}
				if(model.getStatus()!=null){
					exvo.setStatus(model.getStatus()==0?"未认养":(model.getStatus()==1?"认养申请中":"已认养"));
				}
				exportList.add(exvo);
			}
			// 导入excel
			Workbook workbook = ExcelExportUtil.exportExcel(params, ExportExcelModelListVO.class, exportList);
			workbook.write(out);
			out.close();
			System.out.println(DateUtils.getTime());
		} catch (Exception e) {
			//e.printStackTrace();
		}
	}
	private String buildImgPath(String urlPath){
		String[] s = urlPath.split("/treeImages/");
		String fileAbPath = RuoYiConfig.getBLImagesPath() + s[1];
		return fileAbPath;
	}
}
